package com.mingmen.canting.jingli;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mingmen.canting.R;
import com.mingmen.canting.flycotablelayout.flyco.tablayout.SlidingTabLayout;
import com.mingmen.canting.flycotablelayout.flyco.tablayout.listener.OnTabSelectListener;
import com.mingmen.canting.immersionbar.ImmersionBar;
import com.mingmen.canting.util.ViewFindUtils;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class JingLiNewCaiGouDanActivity extends FragmentActivity implements OnTabSelectListener {

    @BindView(R.id.text_return)
    TextView textReturn;
    @BindView(R.id.img_right)
    ImageView imgRight;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.tl_2)
    SlidingTabLayout tl2;
    @BindView(R.id.vp)
    ViewPager vp;
    private Context mContext = this;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {
            "查看采购单", "采购入库单"
    };
    private MyPagerAdapter mAdapter;
    @BindView(R.id.mToolbar)
    Toolbar mToolbar;
    @BindView(R.id.text_center)
    TextView text_center;
    @BindView(R.id.linear_return)
    LinearLayout linear_return;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jinglicaigou);
        ButterKnife.bind(this);

        ImmersionBar.with(this).titleBar(mToolbar)
                .navigationBarColor(R.color.black).init();

        mFragments.add(JingLiCaiGouNewListragment.getInstance(mTitles[0]));
        mFragments.add(JingLiRukuFragment.getInstance(mTitles[1]));
        text_center.setText("采购单");
        View decorView = getWindow().getDecorView();
        SlidingTabLayout tabLayout_2 = ViewFindUtils.find(decorView, R.id.tl_2);
        ViewPager vp = ViewFindUtils.find(decorView, R.id.vp);
        mAdapter = new MyPagerAdapter(getSupportFragmentManager());
        vp.setAdapter(mAdapter);
        tabLayout_2.setViewPager(vp);
        tabLayout_2.setOnTabSelectListener(this);
    }


    @Override
    public void onTabSelect(int position) {

    }

    @Override
    public void onTabReselect(int position) {

    }

    @OnClick({R.id.text_return, R.id.img_right, R.id.tv_right,R.id.linear_return})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.text_return:
                break;
            case R.id.img_right:
                break;
            case R.id.tv_right:
                break;
            case R.id.linear_return:
                finish();
                break;
        }
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }
}
